<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>after</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.js"></script>
</head>

<body>
  <button id="myButton">点击</button>
  <script>
    // _.after(n, func)
    // 当他被调用n或更多次之后将马上触发func
    const button = document.getElementById('myButton');
    let count = 0;
    // 这个方法有致命的缺陷，就是只有在第一次的时候会生效，后面点击第三次
    // 第四次，他还是会生效
    let afterFunc = _.after(3, () => {
      count++;
      console.log("Function called 3 times!", count);
    });
    button.addEventListener('click', afterFunc);
  </script>
</body>

</html>